<extend name='./Base' />
<block name='admin-content-body'>

<div class="admin-content-body">
      <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">菜单管理</strong> / <small>Menus</small></div>
      </div>

      <hr>

      <div class="am-g">
      <form id="add_menu">
        <div class="am-u-sm-12 am-u-md-3">
          <div class="am-form-group">
              <input type="text" name="name" id="name" class="am-form-field" placeholder="菜单名">
          </div>
        </div>
        <div class="am-u-sm-12 am-u-md-3">
          <div class="am-form-group">
              <input type="text" name="icon_class" id="icon_class" class="am-form-field" placeholder="ICON类名">
          </div>
        </div>
        <div class="am-u-sm-12 am-u-md-6">
          <div class="am-input-group">
            <input type="text" class="am-form-field" name="url" value='http://{$_SERVER['HTTP_HOST']}' id="url">
          <span class="am-input-group-btn">
            <button type="submit" class="am-btn am-btn-default" type="button">添加</button>
          </span>
          </div>
        </div>
        </form>
      </div>

      <div class="am-g">
        <div class="am-u-sm-12">
            <table class="am-table am-table-striped am-table-hover">
              <thead>
              <tr>
                <th class="table-title">名称</th>
                <th class="table-type">URL</th>
                <th class="table-type">ICON类名</th>
                <th class="table-type">状态</th>
                <th class="table-set">操作</th>
              </tr>
              </thead>
              <tbody>
              <tr>
                <td>
                  <input type="text" style="border: none;" name="name" value="网站首页" readonly="readonly" size="10"  class="am-form-field">
                </td>
                <td>
                  <input type="text" style="border: none;" size="50" name="link" value="http://{$_SERVER['HTTP_HOST']}"  readonly="readonly" class="am-form-field">
                </td>
                <td>
                  <input type="text" style="border: none;" name="icon_class" size="30" readonly="readonly" value="glyphicon glyphicon-home" class="am-form-field">
                </td>
                <td class="am-hide-sm-only">
                	<button class="am-btn am-btn-primary am-btn-xs" disabled="disabled">可用</button>
                </td>
                <td>系统自带不可操作</td>
              </tr>
		
				<foreach name="menus" item='m'>
              <tr id="{$m['id']}_menu">
                <td>
                  <input type="text" style="border: none;" name="name" value="{$m['name']}" onchange="upl({$m['id']},'name',this)" size="10" class="am-form-field">
                </td>
                <td>
                  <input type="text" style="border: none;" name="link" size="50" value="{$m['url']}" onchange="upl({$m['id']},'url',this)" class="am-form-field">
                </td>
                <td>
                  <input type="text" style="border: none;" name="icon_class" size="30" value="{$m['icon_class']}" onchange="upl({$m['id']},'icon_class',this)" class="am-form-field">
                </td>
                <td class="am-hide-sm-only">
                	<if condition="$m['status'] eq 1">
                <button class="am-btn am-btn-primary am-btn-xs" onclick="changeStatus({$m['id']},this)">
                	可用
                </button>
                <else />
                    <button class="am-btn am-btn-danger am-btn-xs" onclick="changeStatus({$m['id']},this)">停用</button>
                </if>
                </td>
                <td>
                  <div class="am-btn-toolbar">
                    <div class="am-btn-group am-btn-group-xs">
                        <if condition="$_SESSION['userinfo'][0]['username'] eq 'mengfan'"><button  class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" onclick="deletel({$m['id']})"><span class="am-icon-trash-o"></span> 删除</button><else />
                            <button  class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" disabled><span class="am-icon-trash-o"></span> 删除</button></if>
                    </div>
                  </div>
                </td>
              </tr>
             </foreach>

               <tr>
                <td>
                  <input type="text" style="border: none;" name="name" value="留言墙" readonly="readonly"  size="10" class="am-form-field">
                </td>
                <td>
                  <input type="text" style="border: none;" size="50" name="link" value="http://{$_SERVER['HTTP_HOST']}/index/messagewall.html"  readonly="readonly" class="am-form-field">
                </td>
                <td>
                  <input type="text" style="border: none;" name="icon_class" size="30" readonly="readonly" value="glyphicon glyphicon-erase" class="am-form-field">
                </td>
                <td class="am-hide-sm-only">
                	<button class="am-btn am-btn-primary am-btn-xs"  disabled="disabled">可用</button>
                </td>
                <td>系统自带不可操作</td>
              </tr>
              <tr>
                <td>
                  <input type="text" style="border: none;" name="name" value="友情链接" readonly="readonly" size="10" class="am-form-field">
                </td>
                <td>
                  <input type="text" style="border: none;" size="50" name="link" value="http://{$_SERVER['HTTP_HOST']}/index/links.html"  readonly="readonly" class="am-form-field">
                </td>
                <td>
                 <input type="text" style="border: none;" name="icon_class" size="30" readonly="readonly" value="glyphicon glyphicon-link" class="am-form-field">
                </td>
                <td class="am-hide-sm-only">
                	<button class="am-btn am-btn-primary am-btn-xs" disabled="disabled">可用</button>
                </td>
                <td>系统自带不可操作</td>
              </tr>
              <tr>
                <td>
                  <input type="text" style="border: none;" name="name" value="本站标签" readonly="readonly" size="10" class="am-form-field">
                </td>
                <td>
                  <input type="text" style="border: none;" size="50" name="link" value="http://{$_SERVER['HTTP_HOST']}/index/tags.html"  class="am-form-field" readonly="readonly">
                </td>
                <td>
                 <input type="text" style="border: none;" name="icon_class" size="30" readonly="readonly" value="glyphicon glyphicon-tags" class="am-form-field">
                </td>
                <td class="am-hide-sm-only">
                  <button class="am-btn am-btn-primary am-btn-xs" disabled="disabled">可用</button>
                </td>
                <td>系统自带不可操作</td>
              </tr>
              <tr>
                <td>
                  <input type="text" style="border: none;" name="name" value="关于我" readonly="readonly" size="10" class="am-form-field">
                </td>
                <td>
                  <input type="text" style="border: none;" size="50" name="link" value="http://{$_SERVER['HTTP_HOST']}/index/about.html"  readonly="readonly" class="am-form-field">
                </td>
                <td><input type="text" style="border: none;" name="link" size="30" readonly="readonly" value="glyphicon glyphicon-user" class="am-form-field">
                </td>
                <td class="am-hide-sm-only">
                	<button class="am-btn am-btn-primary am-btn-xs" disabled="disabled">可用</button>
                </td>
                <td>系统自带不可操作</td>
              </tr>
                
              </tbody>
            </table>
             <div class="am-fl">
<a href="http://v3.bootcss.com/components/#glyphicons" target="_blank">查找icon</a>
            </div>
        </div>
      </div>
    </div>

</block>

<block name="js">
	<script type="text/javascript">
	function changeStatus(id,obj){
      $.post('__ACTION__',{'id':id,'status':1},function(res){
        if(res.status){
          if(res.data==0){
            //停用
            $(obj).removeClass('am-btn-primary').addClass('am-btn-danger').text('停用');
          }else{
            //可用
            $(obj).removeClass('am-btn-danger').addClass('am-btn-primary').text('可用');
          }
          layer.msg(res.msg);
        }else{
          layer.alert(res.msg,{icon:5});
        }
      });
	}

  function upl(id,field,obj){
    $.post('__ACTION__',{'field':field,'value':obj.value,'id':id,'edit':1},function(res){
      if(res.status){
        layer.msg(res.msg);
      }else{
        layer.alert(res.msg);
      }
    });
  }

  $("#add_menu").submit(function(){
    var name=$("#name").val();
    var link=$("#url").val();
    var icon_class=$("#icon_class").val();
    if($.trim(name)=='' || $.trim(link)=='' || $.trim(icon_class)==''){
      layer.alert('不能为空！');
      return false;
    }
    $.post('__ACTION__',{'name':name,'url':link,'icon_class':icon_class,'add':1},function(res){
      if(res.status){
        layer.msg(res.msg);
        location.reload()
      }else{
        layer.alert(res.msg);
      }
    });
    return false;
  })
   function deletel(id) {
      layer.confirm('确定要删除？不可恢复', {
        btn: ['确定','取消']
      },function(){
        $.post('__ACTION__',{'id':id,'delete':1},function(res){
          if(res.status){
            $("#"+id+"_menu").remove();
            layer.msg(res.msg);
          }else{
            layer.alert(res.msg,{icon:5});
          }
        });
    },function(){})
   }
  </script>
</block>